local pingjian = fk.CreateSkill {
    name = "gai__pingjian",
  }

  local pinjian_skills = {
    ["play"] = {
      "qiangxi", "ol__sanyao", "ol__xuehen", "daoshu",
      "tianyi", "ty__lianji", "ty_ex__wurong", "xuezhao", "ol_ex__mieji",
      "ex__zhiheng", "duliang", "os__gongxin", "minsi",
      "ex__fanjian", "weimeng", "ol_ex__ganlu", "ty__kuangfu", "qice",
      "ty_ex__gongqi", "ty_ex__huaiyi", "qingnang", "anguo", "ex__jieyin",
      "ty_ex__anxu", "ty_ex__mingce", "ziyuan", "ex__lijian", "mingjian", "ex__rende", "mizhao", "dimeng",
      "quhu", "yingshui", "weiwu",
      "ty_ex__yanzhu", "yanxi", "ty__xiongsuan", "chiying", "ty_ex__jianyan", "ol__fenxun", "saojian",
    },
    ["damaged"] = {
      "ty__benyu", "ex__fankui", "ex__ganglie", "ex__yiji", "ex__jianxiong", "ty_ex__enyuan", "jieming",
      "ty_ex__chengxiang", "huituo", "ty__wangxi", "yuce", "zhichi", "ty_ex__zhiyu", "wanggui", "qianlong", "dingcuo",
      "peiqi",
      "os__fupan", "yuqi", "ol__qingxian",  "jini", "ty__hengjiang",  "jijing",  "yachai",
    },
    ["phase_start"] = {
      "ty_ex__zhiyan", "ex__biyue", "zuilun", "mozhi", "ty_ex__bingyi", "miji",
      "juece", "sp__youdi", "kuanshi", "m_ex__jieyue",
      "ty__tunjiang",  "ty__shengxi", "jieli", "ty_ex__zhenjun",
    },
  }

  pingjian.pinjian_skills = pinjian_skills

  Fk:loadTranslationTable{
  ["gai__pingjian"] = "评荐",
  ["#gai__pingjian_trigger"] = "评荐",
  [":gai__pingjian"] = "出牌阶段，或结束阶段，或当你受到伤害后，你可以从对应时机的技能池中随机抽取三个技能，"..
  "然后你选择并视为拥有其中一个技能直到时机结束（每个技能限发动一次）。",

  ["#gai__pingjian"] = "评荐：从三个出牌阶段的技能中选择一个学习",
  ["#gai__pingjian-choice"] = "评荐：选择要学习的技能",

  ["$gai__pingjian1"] = "千帆过尽，评枭雄之谋，论天下分合。",
  ["$gai__pingjian2"] = "三尺毛锋，迎九天之水，琢一世功名。",
  }

local function getPingjianSkills(player, event)
    return table.filter(pinjian_skills[event], function (skill_name)
      return Fk.skills[skill_name] and not player:hasSkill(skill_name, true) and
        not table.contains(player:getTableMark("gai__pingjian_used_skills"), skill_name)
    end)
  end
  
  pingjian:addEffect("active", {
    name = "gai__pingjian",
    prompt = "#gai__pingjian",
    card_num = 0,
    target_num = 0,
    can_use = function(self, player)
      return player:usedEffectTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
      local player = effect.from
      local skills = getPingjianSkills(player, "play")
      if #skills == 0 then return false end
      local choices = table.random(skills, 3)
      local skill_name = room:askToChoice(player, {
        choices = choices,
        skill_name = pingjian.name,
        prompt = "#gai__pingjian-choice",
        detailed = true,
      })
      room:addTableMark(player, "gai__pingjian_used_skills", skill_name)
      room:sendLog{
        type = "#Choice",
        from = player.id,
        arg = skill_name,
        toast = true,
      }
  
      local phase_event = room.logic:getCurrentEvent():findParent(GameEvent.Phase)
      if player:hasSkill(skill_name) or not phase_event then
        return false
      end
  
      room:handleAddLoseSkills(player, skill_name)
      room:addTableMark(player, "pingjian_play_skill-phase", skill_name)
      phase_event:addCleaner(function()
        room:handleAddLoseSkills(player, "-" .. skill_name)
      end)
    end,
  })
  
  pingjian:addEffect(fk.SkillEffect, {
    is_delay_effect = true,
    priority = 2,
    mute = true,
    can_trigger = function(self, event, target, player, data)
      return target == player and table.contains(player:getTableMark("pingjian_play_skill-phase"), data.skill.name)
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local skillName = data.skill.name
      room:removeTableMark(player, "pingjian_play_skill-phase", skillName)
      room:handleAddLoseSkills(player, "-" .. skillName)
    end,
  })
  
  pingjian:addEffect(fk.Damaged, {
    anim_type = "masochism",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(pingjian.name)
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local skills = getPingjianSkills(player, "damaged")
      if #skills == 0 then return false end
      local choices = table.random(skills, 3)
      local skill_name = room:askToChoice(player, {
        choices = choices,
        skill_name = pingjian.name,
        prompt = "#gai__pingjian-choice",
        detailed = true,
      })
      room:addTableMark(player, "gai__pingjian_used_skills", skill_name)
      room:sendLog{
        type = "#Choice",
        from = player.id,
        arg = skill_name,
        toast = true,
      }
  
      room:handleAddLoseSkills(player, skill_name)
      local skel = Fk.skill_skels[skill_name]
      for _, skill in ipairs(skel.effects) do
        if skill:isInstanceOf(TriggerSkill) and skill.event == fk.Damaged and skill:triggerable(event, target, player, data) then
          skill:trigger(event, target, player, data)
        end
      end
      room:handleAddLoseSkills(player, "-"..skill_name)
    end,
  })
  
  pingjian:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(pingjian.name) and player.phase == Player.Finish
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local skills = getPingjianSkills(player, "phase_start")
      if #skills == 0 then return false end
      local choices = table.random(skills, 3)
      local skill_name = room:askToChoice(player, {
        choices = choices,
        skill_name = pingjian.name,
        prompt = "#gai__pingjian-choice",
        detailed = true,
      })
      room:addTableMark(player, "gai__pingjian_used_skills", skill_name)
      room:sendLog{
        type = "#Choice",
        from = player.id,
        arg = skill_name,
        toast = true,
      }
  
      room:handleAddLoseSkills(player, skill_name)
      local skel = Fk.skill_skels[skill_name]
      for _, skill in ipairs(skel.effects) do
        if skill:isInstanceOf(TriggerSkill) and skill.event == fk.EventPhaseStart and skill:triggerable(event, target, player, data) then
          skill:trigger(event, target, player, data)
        end
      end
      room:handleAddLoseSkills(player, "-"..skill_name)
    end,
  })
  
  return pingjian